﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Frm_liste_Demande
    Dim str As String = ""
    Dim check As Boolean = True
    Dim row As DataRow
    Dim strRepas As String = ""

    Public Sub remplirDataset()
        Dim ttcAdjoint As Double = 0
        '-----------------------------------------------------------
        Try
            dse.Tables("Equipement").Rows.Clear()
            Cmd = New SqlCommand("select Equipement,Nbr," &
                                 "Prix_Unitaire," &
                                 "(Clients_Equip.Nbr*Clients_Equip.Prix_Unitaire) as Total " &
                                 "from Clients_Equip " &
                                 "where Clients_Equip.id_dem=" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text), Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Do While Dr.Read()
                    row = dse.Tables("Equipement").NewRow()
                    row("Désignation") = Dr("Equipement")
                    row("Nbr") = Dr("Nbr")
                    row("Prix Unitaire") = Dr("Prix_Unitaire")
                    row("Total") = Dr("Total")
                    dse.Tables("Equipement").Rows.Add(row)
                Loop
            Else
                row = dse.Tables("Equipement").NewRow()
                row("Désignation") = ""
                row("Nbr") = ""
                row("Prix Unitaire") = ""
                row("Total") = ""
                dse.Tables("Equipement").Rows.Add(row)
            End If
            Dr.Close()
            cnClose()
            'tarik
            If eventAdjoinLst.Count > 0 Then
                Dim req = From evAdj In eventAdjoinLst Join adj In lstAdjoints On adj.idAdjoint Equals evAdj.idAdjoint
                          Select evAdj, adj.professino

                For Each r In req
                    row = dse.Tables("Equipement").NewRow()
                    row("Désignation") = r.professino
                    row("Nbr") = 1
                    row("Prix Unitaire") = r.evAdj.prix
                    row("Total") = r.evAdj.prix
                    ttcAdjoint += r.evAdj.prix
                    dse.Tables("Equipement").Rows.Add(row)
                Next

            End If
            'end
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        '------------------------------------------------------------
        Try
            dse.Tables("Informations").Rows.Clear()
            Cmd = New SqlCommand("select nom,prenom,Nom_entreprise,Portable,Type_Client," &
                                 "lieu,Clients_Demande.adresse,Prix_salle,Date_evenement,Date_reservation " &
                                 "from clients,Clients_Demande " &
                                 "where Clients.Id_Client=Clients_Demande.Id_Client " &
                                 "and Clients_Demande.id_dem=" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text), Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Dr.Read()
                row = dse.Tables("Informations").NewRow()
                If Dr("Type_Client") = "Entreprise" Then
                    row("Client") = Dr("Nom_entreprise")
                Else
                    row("Client") = Dr("nom") & " " & Dr("prenom")
                End If
                row("Portable") = Dr("Portable")
                row("Lieu") = Dr("lieu")
                row("Adresse") = Dr("adresse")
                row("Prix salle") = Dr("Prix_salle")
                row("Date evenement") = Format(Dr("Date_evenement"), "dd/MM/yyyy")
                row("Date reservation") = Format(Dr("Date_reservation"), "dd/MM/yyyy")
            End If
            Dr.Close()
            cnClose()
            '------------------------------------------------
            strRepas = ""
            Cmd = New SqlCommand("select repas from Clients_Repas " &
                                 "where [Type]='Plat' " &
                                 "and id_dem=" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text), Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Do While Dr.Read()
                    If strRepas = "" Then
                        strRepas = Dr("repas")
                    Else
                        strRepas = strRepas & " + " & Dr("repas")
                    End If
                Loop
            End If
            Dr.Close()
            cnClose()
            row("Repas") = strRepas
            dse.Tables("Informations").Rows.Add(row)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        '--------------------------------------------------------------
        Try
            dse.Tables("Paiement").Rows.Clear()
            Cmd = New SqlCommand("select sum(Montant) as Montant,Remis from Clients_Paiement_demande " &
                                 "where Id_demande=" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text) &
                                 " and type_paiement='Requis'  " &
                                 "group by Remis ", Con)
            open()
            Dr = Cmd.ExecuteReader()
            row = dse.Tables("Paiement").NewRow()
            If Dr.HasRows = True Then
                Dr.Read()
                row("Montant") = Dr("Montant") + ttcAdjoint
                row("Remis") = Dr("Remis")
            End If
            Dr.Close()
            cnClose()
            '--------------------------------------------
            Cmd = New SqlCommand("select sum(Montant) as Avance from Clients_Paiement_demande " &
                                 "where Id_demande=" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text) &
                                 " and type_paiement='Paye'", Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Dr.Read()
                If Dr("Avance") Is DBNull.Value Then
                    row("Avance") = 0
                Else
                    row("Avance") = Dr("Avance")
                End If
                If row("Montant") Is DBNull.Value And row("Remis") Is DBNull.Value Then
                    row("Montant") = 0
                    row("Remis") = 0
                End If
                row("Reste") = row("Montant") - row("Remis") - row("Avance")
                dse.Tables("Paiement").Rows.Add(row)
            End If
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub
    Public Sub remplir()
        List_tous.Items.Clear()
        If Check_preced.Checked = True And Check_venir.Checked = True Then
            str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client order by Date_evenement"
        ElseIf (Check_preced.Checked = False And Check_venir.Checked = True) Then
            str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and Date_evenement > = CONVERT (date, GETDATE()) order by Date_evenement"
        ElseIf (Check_preced.Checked = True And Check_venir.Checked = False) Then
            str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and Date_evenement < CONVERT (date, GETDATE()) order by Date_evenement"
        Else
            Exit Sub
        End If
        Try
            Cmd = New SqlCommand(str, Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Do While Dr.Read()
                    If Dr("Type_Client") = "Entreprise" Then
                        Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom_entreprise"), Dr("Type_Client"), (Format(Dr("Date_evenement"), "yyyy-MM-dd")), Dr("lieu"), Dr("Type_Reservation"), Dr("Motif_Reservation"), Dr("jour_nuit"), Dr("N_demande"), Dr("id_dem")})
                        If Dr("Annuler") = "true" Then
                            Line.ForeColor = Color.Red
                            List_tous.Items.Add(Line)
                        Else
                            List_tous.Items.Add(Line)
                        End If

                    Else
                        Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom") & "  " & Dr("Prenom"), Dr("Type_Client"), (Format(Dr("Date_evenement"), "yyyy-MM-dd")), Dr("lieu"), Dr("Type_Reservation"), Dr("Motif_Reservation"), Dr("jour_nuit"), Dr("N_demande"), Dr("id_dem")})
                        If Dr("Annuler") = "true" Then
                            Line.ForeColor = Color.Red
                            List_tous.Items.Add(Line)
                        Else
                            List_tous.Items.Add(Line)
                        End If
                    End If

                Loop
            End If
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        txt_rech.Clear()
    End Sub
    Private Sub Frm_liste_Demande_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        comb_selectionnez.SelectedIndex = 0
        txt_rech.Select()

        remplir()
    End Sub

    Private Sub comb_selectionnez_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles comb_selectionnez.KeyPress
        e.Handled = True
    End Sub

    Private Sub Check_venir_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Check_venir.CheckedChanged
        remplir()
    End Sub

    Private Sub Check_preced_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Check_preced.CheckedChanged
        remplir()
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Dim mot As String = ""
        If comb_selectionnez.SelectedItem = "Nom" Then
            mot = "Nom"
        ElseIf comb_selectionnez.SelectedItem = "Prenom" Then
            mot = "Prenom"
        ElseIf comb_selectionnez.SelectedItem = "Cin" Then
            mot = "Cin"
        ElseIf comb_selectionnez.SelectedItem = "Nom de L'entreprise" Then
            mot = "Nom_entreprise"

        ElseIf comb_selectionnez.SelectedItem = "Nom de L'interlocuteur" Then
            mot = "Nom_interlocuteur"
        ElseIf comb_selectionnez.SelectedItem = "Date D'evenement" Then
            mot = "Date_evenement"
        ElseIf comb_selectionnez.SelectedItem = "Num demande" Then
            mot = "N_demande"
        End If

        List_tous.Items.Clear()
        If Check_preced.Checked = True And Check_venir.Checked = True Then
            If mot = "N_demande" Then
                str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and " & mot & " like '" & txt_rech.Text & "'"
            Else
                str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and " & mot & " like '%" & txt_rech.Text & "%'"
            End If
        ElseIf (Check_preced.Checked = False And Check_venir.Checked = True) Then
            str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and Date_evenement > = CONVERT (date, GETDATE()) and " & mot & " like '%" & txt_rech.Text & "%'"
        ElseIf (Check_preced.Checked = True And Check_venir.Checked = False) Then
            str = "select id_dem,N_demande,Type_Client,Nom,Prenom,Nom_entreprise,Date_evenement,lieu,Type_Reservation,Motif_Reservation,jour_nuit,Annuler from Clients,Clients_Demande where Clients.Id_Client=Clients_Demande.Id_Client and Date_evenement < CONVERT (date, GETDATE()) and " & mot & " like '%" & txt_rech.Text & "%'"
        Else
            Exit Sub
        End If

        Try
            Cmd = New SqlCommand(str, Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows = True Then
                Do While Dr.Read()
                    If Dr("Type_Client") = "Entreprise" Then
                        Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom_entreprise"), Dr("Type_Client"), (Format(Dr("Date_evenement"), "yyyy-MM-dd")), Dr("lieu"), Dr("Type_Reservation"), Dr("Motif_Reservation"), Dr("jour_nuit"), Dr("N_demande"), Dr("id_dem")})
                        If Dr("Annuler") = "true" Then
                            Line.ForeColor = Color.Red
                            List_tous.Items.Add(Line)
                        Else
                            List_tous.Items.Add(Line)
                        End If
                    Else
                        Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom") & "  " & Dr("Prenom"), Dr("Type_Client"), (Format(Dr("Date_evenement"), "yyyy-MM-dd")), Dr("lieu"), Dr("Type_Reservation"), Dr("Motif_Reservation"), Dr("jour_nuit"), Dr("N_demande"), Dr("id_dem")})
                        If Dr("Annuler") = "true" Then
                            Line.ForeColor = Color.Red
                            List_tous.Items.Add(Line)
                        Else
                            List_tous.Items.Add(Line)
                        End If
                    End If

                Loop
            End If
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        If txt_rech.Text = "" Then
            remplir()
        End If
    End Sub

    Private Sub List_tous_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles List_tous.DoubleClick
        If liste = "demande" Then
            Frm_Modif_Demande_Clients.MdiParent = Frm_Main
            Frm_Modif_Demande_Clients.Show()

            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        Frm_Modif_Demande_Clients.comb_client.SelectedItem = .Items(.SelectedIndices(i)).SubItems(0).Text

                        Try

                            Cmd = New SqlCommand("Select * From Clients_Demande where id_dem =" & modif, Con)
                            open()
                            Dr = Cmd.ExecuteReader()
                            Do While Dr.Read()
                                Frm_Modif_Demande_Clients.txt_evenement.Text = Dr("Date_evenement")
                                Frm_Modif_Demande_Clients.txt_reserv.Text = Dr("Date_reservation")
                                Frm_Modif_Demande_Clients.txt_adresse.Text = Dr("adresse")
                                Frm_Modif_Demande_Clients.Comb_salle.SelectedItem = Dr("lieu")
                                Frm_Modif_Demande_Clients.Combo_type_reserv.SelectedItem = Dr("Type_Reservation")
                                Frm_Modif_Demande_Clients.Comb_motif_reserv.SelectedItem = Dr("Motif_Reservation")
                                Frm_Modif_Demande_Clients.txt_n_demande.Text = Dr("N_demande")
                                Frm_Modif_Demande_Clients.txt_remarq.Text = Dr("Remarque")
                                Frm_Modif_Demande_Clients.txt_prix_salle.Text = Dr("Prix_salle")
                                Frm_Modif_Demande_Clients.txt_NomA.Text = Dr("Marie")
                                Frm_Modif_Demande_Clients.txt_NomB.Text = Dr("Mariee")

                                If Dr("jour_nuit") = "Jour" Then
                                    Frm_Modif_Demande_Clients.Radio_jour.Checked = True
                                Else
                                    Frm_Modif_Demande_Clients.Radio_nuit.Checked = True
                                End If

                            Loop
                            Dr.Close()
                            cnClose()
                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try
                        '-------------------------------------------------------------------------------------
                        Try
                            Frm_Modif_Demande_Clients.List_Repas.Items.Clear()
                            Cmd = New SqlCommand("Select * From Clients_Repas where id_dem =" & modif, Con)
                            open()
                            Dr = Cmd.ExecuteReader()
                            Do While Dr.Read()
                                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Repas")})
                                Frm_Modif_Demande_Clients.List_Repas.Items.Add(Line)

                            Loop
                            Dr.Close()
                            cnClose()
                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try
                        '-------------------------------------------------------------------------------------
                        Try
                            Frm_Modif_Demande_Clients.List_tous.Items.Clear()
                            Cmd = New SqlCommand("Select * From Clients_Equip where id_dem =" & modif, Con)
                            open()
                            Dr = Cmd.ExecuteReader()
                            Do While Dr.Read()
                                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Equipement"), Dr("Prix_Unitaire"), Dr("Nbr"), Dr("Prix_Total"), Dr("Remarq")})
                                Frm_Modif_Demande_Clients.List_tous.Items.Add(Line)

                            Loop
                            Dr.Close()
                            cnClose()
                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try
                    Next
                End If
            End With

        ElseIf liste = "loc" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Paiement_Clients.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Paiement_Clients.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text

                        Frm_Paiement_Clients.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text
                        Frm_Paiement_Clients.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Paiement_Clients.txt_demande.Text = .Items(.SelectedIndices(i)).SubItems(7).Text
                        Dim idd As Integer = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Try

                            Cmd = New SqlCommand("Select Date_reservation From Clients_Demande where id_dem =" & idd, Con)
                            open()
                            Dr = Cmd.ExecuteReader()
                            Do While Dr.Read()

                                Frm_Paiement_Clients.Date_requi.Text = Dr("Date_reservation")
                                Frm_Paiement_Clients.Date_paye.Text = Dr("Date_reservation")

                            Loop
                            Dr.Close()
                            cnClose()
                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try

                    Next
                End If
            End With

        ElseIf liste = "Equi" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Equipements_Utilises.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Equipements_Utilises.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text
                        Frm_Equipements_Utilises.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Equipe_Travail.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text
                        Frm_Equipements_Utilises.affiche()
                    Next

                End If
            End With

        ElseIf liste = "Pers" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1

                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Equipe_Travail.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Equipe_Travail.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text
                        Frm_Equipe_Travail.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Equipe_Travail.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text
                        Frm_Equipe_Travail.affiche()
                    Next

                End If
            End With

        ElseIf liste = "Pers_pai" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Paiement_Personnels.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Paiement_Personnels.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text
                        Frm_Paiement_Personnels.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Paiement_Personnels.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text
                        Frm_Paiement_Personnels.vider()
                        Frm_Paiement_Personnels.affi()
                        'Frm_Paiement_Personnels.affiche_paye()
                    Next

                End If
            End With
        ElseIf liste = "demande fornisseur" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Demande_Fournisseurs.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Demande_Fournisseurs.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text
                        Frm_Demande_Fournisseurs.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Demande_Fournisseurs.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text
                        Frm_Demande_Fournisseurs.List_tous.Items.Clear()
                        Frm_Demande_Fournisseurs.List_forni.Items.Clear()
                        Frm_Demande_Fournisseurs.affiche()

                        ' Frm_Demande_Fournisseurs.vider()
                        'Frm_Demande_Fournisseurs.affi()
                        'Frm_Demande_Fournisseurs.affiche_paye()
                    Next

                End If

            End With
        ElseIf liste = "demande fornisseur paiement" Then
            With List_tous
                If .SelectedIndices.Count > 0 Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        id_event = .Items(.SelectedIndices(i)).SubItems(8).Text
                        Frm_Paiement_Fournisseurs.txt_client.Text = ""
                        Frm_Paiement_Fournisseurs.txt_client.Text = .Items(.SelectedIndices(i)).SubItems(0).Text
                        Frm_Paiement_Fournisseurs.txt_date_evenement.Text = .Items(.SelectedIndices(i)).SubItems(2).Text
                        Frm_Paiement_Fournisseurs.txt_lieu.Text = .Items(.SelectedIndices(i)).SubItems(3).Text
                        Frm_Paiement_Fournisseurs.jour_nuit.Text = .Items(.SelectedIndices(i)).SubItems(6).Text

                        '-------------------------------Remplir combo fornisseur---------------------------------'
                    Next

                End If
            End With
        End If

        Me.Close()
    End Sub

    Private Sub Check_Annuler_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Check_Annuler.CheckedChanged
        Try
            If List_tous.SelectedItems.Count > 0 And check Then
                Dim stre As String = ""
                Dim id As Integer = List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text
                If Check_Annuler.Checked = True Then
                    stre = "true"
                    List_tous.Items(List_tous.SelectedIndices(0)).ForeColor = Color.Red
                ElseIf Check_Annuler.Checked = False Then
                    stre = "false"
                    List_tous.Items(List_tous.SelectedIndices(0)).ForeColor = Color.Black
                End If
                Cmd = New SqlCommand("update Clients_Demande set Annuler='" & stre & "'" & _
                 " Where id_dem=" & id, Con)
                open()
                Cmd.ExecuteNonQuery()
                cnClose()
                'Else
                '    MsgBox("Choisi un événement", MsgBoxStyle.Critical, "Erreur")
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Private Sub List_tous_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles List_tous.SelectedIndexChanged
        Try
            If List_tous.SelectedItems.Count > 0 Then
                Cmd = New SqlCommand("Select Annuler From Clients_Demande where id_dem =" & CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text), Con)
                open()
                Dr = Cmd.ExecuteReader()
                Dr.Read()
                If Dr("Annuler") = "true" Then
                    check = False
                    Check_Annuler.Checked = True
                    check = True
                ElseIf Dr("Annuler") = "false" Then
                    check = False
                    Check_Annuler.Checked = False
                    check = True
                End If
                Dr.Close()


                'tarik
                modif = List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text
                'remplir les adjoints de l'événement
                eventAdjoinLst = New List(Of adjointEvents)
                remplirLstAdjoint(modif)
                'end
                cnClose()
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub


    Private Sub btn_bon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_bon.Click
        Try
            If List_tous.SelectedItems.Count > 0 Then
                remplirDataset()
                id_event = CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(8).Text)
                numDemande = CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(7).Text)
                bon = "liste demande"
                frm_bon.MdiParent = Frm_Main
                frm_bon.Show()
                Me.Close()

            Else

            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try

    End Sub
End Class